/* eslint-disable @typescript-eslint/no-explicit-any */
import { postRequest, getRequest, buildResult, customError } from './request'
import { ReturnType } from '../interface';
// import { randomString } from '../utils/common'

interface ResponseData<T> {
    code: number;
    data: T;
    msg: string;
    reqNo: string
}

export const post = async <T = any>(url: string, params?: object, headers?: { [key: string]: string }): Promise<ReturnType<T | undefined>> => {
    try {
        const result = await postRequest(url, params, headers) as unknown as ResponseData<T>;
        return buildResult(result.data, result.code, result.msg)
    } catch (error: any) {
        return customError(error)
    }

}

export const get = (url: string, params?: object) => {
    return getRequest(url, params)
}

export {
    buildResult,
    customError
};
export type { ReturnType };
